<?php
/**
 * Instalacja obslugiwanych domen
 * Możliwość wskazania kilka domen na jedną
 * 
 */
	if(isset($_SERVER['HTTP_HOST'])) {
		$d__ = preg_replace ('#^www.#', '', $_SERVER['HTTP_HOST']);
		
	}else{
		$d__ = 'seo.pzco';
	}
	
	
	if (!defined('HOST')) {

		$map = array(
			"seo.pzco"	=>	array('name'=>'seo.pzco','status'=>'active','lang'=>'pol','redirect'=>false,'main_domain'=>null),
			"pzco.seosolution.pl"	=>	array('name'=>'seo.pzco','status'=>'active','lang'=>'pol','redirect'=>false,'main_domain'=>null)
		);		
		
		if (array_key_exists($d__,$map)) {	
			
			// przekierowanie 301
			if($map[$d__]['redirect']){
				header('HTTP/1.1 301 Moved Permanently');
				header('Location: http://www.'.$map[$d__]['main_domain'].$_SERVER['REQUEST_URI']);
				header('Connection: close');
			}		
			
		    define('HOST',$map[$d__]['name']);
		    Configure::write('Config.host', $map[$d__]['name']);
		    Configure::write('Config.status', $map[$d__]['status']);		    
		}else{
			header('HTTP/1.1 301 Moved Permanently');
			header('Location: http://www.seosolution.pl'.$_SERVER['REQUEST_URI']);
			header('Connection: close');
			die;
		}
	}
	
	/**
	 * definicja sciezki do zapisywania plikow 
	 * dla modelu upload
	 */
	if (!defined('UPLOAD_PATH')) {
	    define('UPLOAD_PATH', 'files/'.HOST.'/upload');
	}	
	
	
/**
 * Instalacja wersji jezykowej
 * @var unknown_type
 */	
    $languages = array(
    	 'pol'=>array('name'=>__("Polih",true))
    	,'eng'=>array('name'=>__("Angielski",true))
    );
	
	
	// zainstalowane jezyki
	Configure::write('Config.languages', $languages);	

	Configure::write('Config.default_lang', $map[$d__]['lang']);
	
/**
 * Definicja grup uzytkowników
 */
	$users_groups = array(
		'admin'=>array('name'=>__("Administrator",true))
		,'manag'=>array('name'=>__("Menadzer",true))		
		,'emplo'=>array('name'=>__("Pracownik",true))		
		,'copyr'=>array('name'=>__("Coypraiter",true))
		,'users'=>array('name'=>__("Uzytkownicy",true))
		,'firms'=>array('name'=>__("Firmy",true))
	);
	Configure::write('Config.users_groups', $users_groups);
	
/**
 * Google
 */

	Configure::write('Config.google.path',"files/".HOST."/google/");
	if(isset($_SERVER['HTTP_HOST']))Configure::write('Config.google.apikey',"apikey.".preg_replace ('#^www.#', '', $_SERVER['HTTP_HOST']).".txt");
	if(isset($_SERVER['HTTP_HOST']))Configure::write('Config.google.analytics',"analytics.".preg_replace ('#^www.#', '', $_SERVER['HTTP_HOST']).".txt");

	
	/**
	 * uniqiname for uploaded file
	 * @param $fileName
	 */
	function uniqid_file_name($fileName){
		preg_match("/\.([^\.]+)$/", $fileName, $matches);
		return uniqid('file_').'.'.strtolower($matches[1]);
	}